<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
     <%@page import="java.io.*" %>
     <%@page import="mavenWebProject.userMapper" %>
     <%@page import="mavenWebProject.user" %>
     <%@page import="mavenWebProject.productsMapper" %>
     <%@page import="mavenWebProject.products" %>
     <%@page import="mavenWebProject.order" %>
     <%@page import="mavenWebProject.car" %>
     <%@page import="java.util.*" %>
     <%@page import="javax.servlet.*" %>
     <%@page import="org.apache.ibatis.io.Resources" %>
     <%@page import="org.apache.ibatis.session.SqlSession"%>
     <%@page import="org.apache.ibatis.session.SqlSessionFactory" %>
     <%@page import="org.apache.ibatis.session.SqlSessionFactoryBuilder" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>管理员</title>
</head>

<style>
    body{font-family: 楷体;font-size: 18px;}

    table[id="tableGuide"]{
        position: absolute;
        top:0%;
        left:0%;
        width:100%;
        height:200px;
        background-color: black;
        color:white;
    }

    table[id="tableShowSold"]{display:block;position: absolute;top:60px;left:0px;background-color:rgb(241,245,251);width:100%;height:700px;border-top-left-radius: 10px;border-top-right-radius: 10px;}
    
    a:link{color:white;text-decoration:none;padding:10px;}
    a:hover{padding:8px;border-radius: 5px;background-color: aliceblue;color:black;}
    a:visited:hover{color:black;}
    a:visited{color:white;}
    a[id="manageProducts"]{color:white;}
    a[id="manageProducts"]:hover{color:black;}
    a[id="tableProductsManageSearchButton"]{margin-left:20px;padding:8px;background-color:white;border-radius:8px;}

    p{margin:0px;}
</style>

<body>
  	<%
    String username=String.valueOf(session.getAttribute("username"));
    %>
	<table id="tableGuide" border="0" cellspacing="10px">
        <tr></tr>
 		<tr><td width="30px"></td><td width="60px"><a href="managerScene.jsp">首页</a></td><td width="100px"><a id="hrefa" href="managerManageProducts.jsp">商品管理</a></td><td width="100px"><a id="hrefa" href="managerManageOrder.jsp">订单管理</a></td><td width="100px"><a id="hrefa" href="managerShowSold.jsp">销量排行</a></td><td width="100px"><a id="hrefa" href="managerManagePurchaser.jsp">用户情况</a></td><td width="100px"></td><td align="right" width="800px">欢迎您：<font style="font-size:24px;margin:10px;color:cyan;"><%=username%></font>&nbsp;&nbsp;<a style="color:red" onClick="exit()">注销</a></td></tr>        
 		<tr><td colspan="8" height="150px"></tr>
    </table>

    <table id="tableShowSold" border="0">
    <form id="showSoldForm">
        <tr><td width="150px" valign="bottom" height="50px"><font style="color:blue;font-size:22px;font-weight:bolder;margin-top:20px;margin-left:10px;">|销量排行</font></td><td width="1400px">&nbsp;</td></tr>
        <tr><td height="60px">&nbsp;</td><td><input placeholder="输入您想查看的商品名称或类别" id="searchShowSold" name="searchShowSold" type="text" style="border:1px solid black;width:400px;height:30px;border-radius:5px;background-color:rgb(0,0,0,0);"><a style="margin-left:20px;border-radius:8px;color:white;margin-top:10px;background-color:blueviolet;padding-right:15px;padding-left:15px;padding:8px;" onClick="searchShowSold()">查找</a>
        <a style="margin-left:20px;border-radius:8px;color:white;margin-top:10px;background-color:blueviolet;padding-right:15px;padding-left:15px;padding:8px;" href="managerShowSold.jsp">重置</a>
        <br>
        </td></tr>
        <tr><td>&nbsp;</td><td>
            <table border="0">
                <tr align="center" height="60px" style="font-size:20px;font-weight:bold;"><td rowspan="999" width="200px"></td><td>商品图片</td><td>商品名称</td><td width="100px">价格（元）</td><td width="150px">库存（件）</td><td width="100px">销量（件）</td><td width="100px">种类</td></tr>
                <tr><td colspan='7'><hr></td></tr>
                <%
                String resource = "mybatis-config.xml";
                request.setCharacterEncoding("utf-8");
            	InputStream inputStream = Resources.getResourceAsStream(resource);
            	SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
            	SqlSession sqlsession=sqlSessionFactory.openSession();
            	productsMapper productsMapper=sqlsession.getMapper(productsMapper.class);
            	List<products> products=productsMapper.selectOrderedBySold();
            	int id=0;String name="";String img="";int price=0;int storage=0;int sold=0;String kind="";String for_group="";
                
                String search=request.getParameter("searchShowSold");
                
                for(products s:products){
                	id=s.getId();name=s.getName().trim();img=s.getImg().trim();price=s.getPrice();storage=s.getStorage();sold=s.getSold();kind=s.getKind().trim();for_group=s.getFor_group().trim();
                	if(kind.contentEquals("clothing") && for_group.contentEquals("m")){img="shopCenterImgs/man-clothing/"+img;}
            		else if(kind.contentEquals("clothing") && for_group.contentEquals("w")){img="shopCenterImgs/female-clothing/"+img;}
            		else if(kind.contentEquals("bag")){img="shopCenterImgs/bag/"+img;}
            		else if(kind.contentEquals("jewelry")){img="shopCenterImgs/jewelry/"+img;}
                	if(kind.contentEquals("clothing")){kind="服装";}else if(kind.contentEquals("bag")){kind="背包";}else if(kind.contentEquals("jewelry")){kind="珠宝";}
                	if(search!=null){
                		if(name.contains(search) || kind.contains(search)){
           					out.println("<tr align='center'><td><img src='"+img+"' width='150px' height='150px'></td><td>"+name+"</td><td>￥"+price+"</td><td>"+storage+"</td><td><font style='font-size:25px;color:red;'>"+sold+"</font></td><td>"+kind+"</td></tr><tr><td colspan='7'><hr></td></tr>");
                		}
                	}else{
       					out.println("<tr align='center'><td><img src='"+img+"' width='150px' height='150px'></td><td>"+name+"</td><td>￥"+price+"</td><td>"+storage+"</td><td><font style='font-size:25px;color:red;'>"+sold+"</font></td><td>"+kind+"</td></tr><tr><td colspan='7'><hr></td></tr>");
                	}
                }
                %>
            </table>    
        </td></tr>
    </form>
    </table>
    <script>
    	function searchShowSold(){
    		document.getElementById("tableShowSold").method="post";document.getElementById("showSoldForm").action="managerShowSold.jsp?search=1";document.getElementById("showSoldForm").submit();
    	}
    </script>
    


</body>
</html>